const apiHostUrl = process.env.API_HOST_URL ? process.env.API_HOST_URL : "http://172.22.223.68:8091";


/**
 * 装配抽奖
 * @param activityId 活动ID
 */
export const activityStrategyArmory = (activityId? : number) =>{
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/activity/armory?activityId=${activityId}`, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
            },
        });
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    }catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}

/**
 * 查询抽奖奖品列表
 */
export const queryRaffleAwardList = (userId? : string, activityId? : number, awardLockCheckFlag? :string) =>{
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/strategy/queryRaffleAwardList`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                userId: userId,
                activityId: activityId,
                awardLockCheckFlag: awardLockCheckFlag
            })
        });
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    } catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}

/**
 * 随机抽奖接口
 */
export const randomRaffle = (strategyId?: number) => {
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/randomRaffle`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json;charset=utf-8'
            },
            body: JSON.stringify({
                strategyId: strategyId
            })
        })
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    } catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}

/**
 *  执行抽奖操作
 * @param userId 用户id
 * @param activityId 活动id
 * @returns 
 */
export const draw = (userId? : string, activityId? :number) =>{
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/activity/draw`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json;charset=utf-8'
            },
            body: JSON.stringify({
                userId: userId,
                activityId: activityId
            })
        })
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    } catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}
/**
 * 签到接口
 * @param userId
 */
export const calendarSignRebate=(userId? : string)=>{
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/activity/signRebate?userId=${userId}`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json;charset=utf-8'
            }
        })
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    } catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}
/**
 * 签到结果查询
 * @param userId
 */
export const isCalendarSignRebate=(userId? : string)=>{
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/activity/isCalendarSignRebate?userId=${userId}`, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json;charset=utf-8'
            }
        })
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    } catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}
/**
 * 查询账户额度接口
 * @param userId 用户ID
 * @param activityId 活动ID
 */
export const queryAccountSurplus = (userId? : string, activityId? : number) =>{
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/activity/queryAccountSurplus?userId=${userId}&activityId=${activityId}`, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
            }
        })
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    }catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}
/**
 * 查询权重抽奖配置
 * @param userId
 * @param activityId
 */
export const queryRaffleStrategyRuleWeight = (userId? : string, activityId? : number) =>{
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/strategy/queryRaffleStrategyRuleWeight?userId=${userId}&activityId=${activityId}`, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
            }
        })
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    }catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}

/**
 * 中奖列表
 * @param userId
 * @param activityId
 */
export const queryAwardRecord = (userId? : string, activityId? : number) =>{
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/activity/queryAwardRecord?userId=${userId}&activityId=${activityId}`, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/json',
            }
        })
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    }catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}

/**
 * 查询用户积分额度
 * @param userId
 */
export const queryUserCreditAccount = (userId?: string)=>{
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/activity/queryUserCreditAccount?userId=${userId}`, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        })
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    } catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}

export const querySkuProductListByActivityId = (activityId?: number)=>{
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/activity/querySkuProductListByActivityId?activityId=${activityId}`, {
            method: 'GET',
            headers: {
                'Content-Type': 'application/x-www-form-urlencoded'
            }
        })
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    } catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}

export const creditPayExchangeSku = (userId?: string, sku?: number) => {
    try {
        return fetch(`${apiHostUrl}/api/bigmarket/raffle/activity/creditPayExchangeSku`, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json;charset=utf-8'
            },
            body: JSON.stringify({
                userId: userId,
                sku: sku
            })
        })
        // eslint-disable-next-line @typescript-eslint/no-unused-vars
    } catch (error) {
        return fetch("{\n" +
            "    \"code\": \"0001\",\n" +
            "    \"info\": \"调用失败\",\n" +
            "    \"data\": [\n" +
            "}");
    }
}


